﻿<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <div id="" style="width:400px; height:600px;background:#ff0000;">
        <canvas id="the-canvas" style="width:400px; height:500px"></canvas>
    </div>

</body>
<script src="~/Content/build/jquery-1.8.2.min.js"></script>
<script src="~/Content/build/pdf.js"></script>
<script src="~/Content/build/pdf.worker.js"></script>
<script>
    function Show(content) {
        // atob() is used to convert base64 encoded PDF to binary-like data.
        // (See also https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/
        // Base64_encoding_and_decoding.)
        //var pdfData = atob(content);



        // Using DocumentInitParameters object to load binary data.
        var loadingTask = PDFJS.getDocument({
            url: "http://localhost:49349/api/file/download2",
            rangeChunkSize:65536 * 8
        });
        loadingTask.promise.then(function (pdf) {
            console.log('PDF loaded');

            // Fetch the first page
            var pageNumber = 1;
            pdf.getPage(pageNumber).then(function (page) {
                console.log('Page loaded');

                var scale = 1.5;
                var viewport = page.getViewport(scale);

                // Prepare canvas using PDF page dimensions
                var canvas = document.getElementById('the-canvas');
                var context = canvas.getContext('2d');
                canvas.height = viewport.height;
                canvas.width = viewport.width;

                // Render PDF page into canvas context
                var renderContext = {
                    canvasContext: context,
                    viewport: viewport
                };
                var renderTask = page.render(renderContext);
                renderTask.then(function () {
                    console.log('Page rendered');
                });
            });
        }, function (reason) {
            // PDF loading error
            console.error(reason);
        });
    }

    Show();
</script>

</html>